package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysEquipment;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISysEquipmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author: 陈宇寰
 * @date: 2021-10-14 10:59:11
 * @params:
 * @return:
 * @description: 设备管理接口层
 */
@RestController
@RequestMapping("/sys/equipment")
public class SysEquipmentController extends BaseController {

    @Resource
    private ISysEquipmentService equipmentService;

    @PostMapping
    public AjaxResult addNewEquipment(@Valid @RequestBody SysEquipment s) {
        return AjaxResult.success(equipmentService.addNewEquipment(s));
    }

    @PutMapping
    public AjaxResult updateEquipment(@RequestBody SysEquipment s) {
        return AjaxResult.success(equipmentService.updateEquipment(s));
    }

    @DeleteMapping
    public AjaxResult deleteEquipmentMultiByIds(@RequestBody Map map) {
        List<Long> ids = (List<Long>) map.get("ids");
        if (ObjectUtil.isEmpty(ids)) {
            return AjaxResult.success("无数据");
        }
        return AjaxResult.success(equipmentService.deleteEquipmentMultiByIds(ids));
    }

    @GetMapping
    public TableDataInfo records(SysEquipment s) {
        startPage();
        List<SysEquipment> equipments = equipmentService.records(s);
        return getDataTable(equipments);
    }
}
